package com.lu.system.controller;

import com.lu.common.quartz.utils.QuartzManager;
import com.lu.task.domain.ScheduleJob;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/quartzManage")
public class QuartzManageController {

    @Autowired
    private QuartzManager quartzManager;

    @GetMapping("/update")
    @ResponseBody
    public String updateQuartz(String cron){
        ScheduleJob scheduleJob = new ScheduleJob();
        scheduleJob.setJobName("MailTask");
        scheduleJob.setJobGroup("group1");
        scheduleJob.setJobStatus("1");
        scheduleJob.setCronExpression(cron);
        scheduleJob.setDescription("test01");
        scheduleJob.setBeanClass("com.lu.common.task.MailTask");
//        scheduleJob.setIsConcurrent("");
        scheduleJob.setMethodName("");
        scheduleJob.setSpringBean("");

        try {
            quartzManager.updateJobCron(scheduleJob);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
        return cron;
    }


}
